package com.totoro.tymapping.enums;

import com.totoro.tymapping.executor.command.MainCommandExecutor;
import com.totoro.tymapping.executor.command.impl.HelpExecutor;
import com.totoro.tymapping.executor.command.impl.ReloadExecutor;
import com.totoro.tymapping.executor.command.impl.StartExecutor;
import com.totoro.tymapping.executor.command.impl.StopExecutor;

/**
 * @author Totoro
 * @version 0.1.0
 * @date 2025/8/13 - 17:49
 * @description 命令执行器枚举
 **/
public enum CommandExecutorEnum {
    HELP("help", new HelpExecutor()),
    START("start", new StartExecutor()),
    STOP("stop", new StopExecutor()),
    RELOAD("reload", new ReloadExecutor());

    private String commandType;
    private MainCommandExecutor mainCommandExecutor;

    CommandExecutorEnum(String commandType, MainCommandExecutor mainCommandExecutor) {
        this.commandType = commandType;
        this.mainCommandExecutor = mainCommandExecutor;
    }

    public static MainCommandExecutor getMainCommandExecutor(String commandType) {
        for (CommandExecutorEnum commandExecutorEnum : CommandExecutorEnum.values()) {
            if (commandExecutorEnum.commandType.equalsIgnoreCase(commandType)) {
                return commandExecutorEnum.mainCommandExecutor;
            }
        }
        return HELP.mainCommandExecutor;
    }

    public String getCommandType() {
        return commandType;
    }

    public MainCommandExecutor getMainCommandExecutor() {
        return mainCommandExecutor;
    }
}
